import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:number_spark_flutter/pages/ns_main/ns_main_logic.dart';
import 'package:number_spark_flutter/routes/ns_app_pages.dart';
import 'package:number_spark_flutter/style/ns_style.dart';
import 'package:number_spark_flutter/utils/ns_user_utils.dart';
import 'package:number_spark_flutter/widgets/brick/ns_brick.dart';
import 'ns_home_logic.dart';

class NSHomePage extends StatelessWidget {
  NSHomePage({Key? key}) : super(key: key);

  final logic = Get.put(NSHomeLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Stack(
        children: [
          const NSImage(
            assetImage: 'img_bg_home.png',
            width: double.infinity,
          ),
          Column(
            children: [
              const Spacer(),
              NSRow(
                mainAxisAlignment: MainAxisAlignment.center,
                margin: EdgeInsets.only(bottom: 40.w),
                children: [
                  NSImage(
                    assetImage: 'img_bg_home_left_btn.png',
                    width: 164.w,
                    onTap: () {
                      Get.toNamed(NSRoutes.single);
                    },
                  ),
                  NSStack(
                    alignment: Alignment.topRight,
                    clipBehavior: Clip.none,
                    children: [
                      NSImage(
                        assetImage: 'img_bg_home_right_btn.png',
                        width: 164.w,
                      ),
                      GetBuilder<NSHomeLogic>(
                        builder: (logic) {
                          return Positioned(
                            right: -9,
                            top: -35,
                            child: Stack(
                              alignment: Alignment.bottomCenter,
                              children: [
                                NSImage(
                                  assetImage: NSUserUtils.getUserDoubleGameFreeCount() > 0 ? 'icon_home_btn_flag_free.png' : 'icon_home_btn_flag_coin.png',
                                  width: 72.w,
                                ),
                                if (NSUserUtils.getUserDoubleGameFreeCount() > 0)
                                  Transform.rotate(
                                    angle: -0.1,
                                    child: NSStack(
                                      margin: EdgeInsets.only(bottom: 15.w, left: 5.w),
                                      clipBehavior: Clip.none,
                                      children: [
                                        NSText(
                                          text: 'X${NSUserUtils.getUserDoubleGameFreeCount()}',
                                          fontSize: 13.sp,
                                          fontFamily: 'Modak-Regular',
                                          // textColor: Colors.white,
                                          foreground: Paint()
                                            ..style = PaintingStyle.stroke
                                            ..strokeWidth = 1.5
                                            ..color = kAppColor('#FF2D9E16'),
                                        ),
                                        NSText(
                                          text: 'X${NSUserUtils.getUserDoubleGameFreeCount()}',
                                          fontSize: 13.sp,
                                          fontFamily: 'Modak-Regular',
                                          textColor: Colors.white,
                                        )
                                      ],
                                    ),
                                  )
                              ],
                            ),
                          );
                        },
                        id: idFreeCount,
                      )
                    ],
                    onTap: () {
                      logic.doClickDoubleGame();
                    },
                  )
                ],
              )
            ],
          )
        ],
      ),
    );
  }
}
